'''
https://leetcode.cn/problems/subarray-sum-equals-k/description/
'''
from typing import List


class Solution:
    def subarraySum(self, nums: List[int], aim: int) -> int:
        dic = {0:1}
        sum = 0
        ans = 0
        for i, num in enumerate(nums):
            sum += num
            ans += dic.get(sum - aim, 0)
            dic[sum] = dic.get(sum, 0) + 1
        return ans
